﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;
using System.Diagnostics;
using BluePortal.Medias.Core;
using System.Linq.Expressions;
using BluePortal.Framework;

namespace BluePortal.Medias.Core
{
    public class AbstractBusinessComponent
    {
        EntitiesDataContext _Context = null;
        public EntitiesDataContext Context
        {
            get { 
                if (_Context == null) 
                {
                    _Context = new EntitiesDataContext(Properties.Settings.Default.BluePortalConnectionString);
                    _Context.DeferredLoadingEnabled = false;
                } 
                return _Context; }
            set { _Context = value; }
        }

        protected void AssertNotNull(object value, string paramName)
        {
            if (value == null)
                throw new ArgumentNullException(paramName, "can't be null");
        }

        public FindResult<T> ToFindResult<T>(IQueryable<T> query, FindParameters param)
        {
            return FindResultHelper.ToFindResult<T>(query, param);
        }
    }

    public class TraceContext : TextWriter
    {

        public override Encoding Encoding
        {
            get { return Encoding.Unicode; }
        }

        public override void Write(string value)
        {

            Trace.Write(value);
        }

        public override void WriteLine(string value)
        {
            Trace.WriteLine(value);
        }
    }


}
